<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, maximum-scale=1.0, initial-scale=1, user-scalable=0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>数据处理脚本--清空患者信息</title>
</head>
<body>
<div id="app">
    <form action="" method="post" id="submitForm">
        服务版本：
        <input id="oms_prod" name="mysql_serve" type="radio" data-text="正式OMS" value="oms_prod"><label for="oms_prod">正式OMS</label>
        <input id="oms_test" name="mysql_serve" type="radio" data-text="测试OMS" value="oms_test"><label for="oms_test">测试OMS</label>
        <input id="dps_prod" name="mysql_serve" type="radio" data-text="正式DPS" value="dps_prod"><label for="dps_prod">正式DPS</label>
        <input id="dps_test" name="mysql_serve" type="radio" data-text="测试DPS" value="dps_test"><label for="dps_test">测试DPS</label>
        <br>
        <br>
    </form>
    <ul id="list"></ul>
</div>
</body>

<!-- 引入 Vue 和 Vant 的 JS 文件 -->
<script src="{{ asset('js/url.min.js') }}"></script>
<script src="{{ asset('js/jquery.min.js') }}"></script>
<script>
    $(function () {

        $("input:radio[name='mysql_serve']").change(function(){

            $.ajax({
                type: "GET",
                url: "/data/flup/list",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: {
                    mysql_server: $(this).val()
                },
                dataType: "json",
                beforeSend: function () {
                    $('#list').html('<li>数据加载中</li>')
                },
                success: function(data) {
                    if (data.code === 0) {
                        let html = ''
                        $.each(data.data, function (index, item) {
                            html += '<li style="height: 30px; line-height: 30px">'+item.template_project_name+' <button type="button" data-id="'+item.data_id+'" class="del" style="margin-left: 10px">删除</button></li>'
                        })
                        $('#list').html(html)
                    } else {
                        alert(data.msg)
                    }
                },
                error: function(err) {
                    alert('系统错误，请联系技术')
                }
            })
        })

        $('#list').on('click', '.del', function () {

            var pwd = prompt("输入执行密码")
            if (pwd == '' || pwd == undefined) {
                alert('请输入执行密码');
                return false
            }

            if ($("input[type='radio']:checked").val() == '' || $("input[type='radio']:checked").val() == undefined) {
                alert('请选择服务版本');
                return false
            }

            var id = $(this).data('id')
            if (id == '' || id == undefined || id == 'undefined') {
                alert('数据异常')
                return false
            }

            $.ajax({
                type: "POST",
                url: "/data/flup/del",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: {
                    mysql_server: $("input[type='radio']:checked").val(),
                    data_id: id,
                    pwd: pwd
                },
                dataType: "json",
                success: function(data) {
                    if (data.code === 0) {
                        alert('数据处理成功')
                        window.location.reload()
                    } else {
                        alert(data.msg)
                    }
                },
                error: function(err) {
                    alert('系统错误，请联系技术')
                }
            })

        })

    })
</script>
</html>
